package web

import (
	"github.com/gin-gonic/gin"
	sys_config "go-iot-gateway/internal/sys/config"
	"go-iot-gateway/internal/web/dataview"
	"net/http"
)

func auth(r *gin.Engine) {
	//var secrets = gin.H{
	//	"foo":    gin.H{"email": "foo@bar.com", "phone": "123433"},
	//	"austin": gin.H{"email": "austin@example.com", "phone": "666"},
	//	"lena":   gin.H{"email": "lena@guapa.com", "phone": "523443"},
	//}
	r.Group("/admin", gin.BasicAuth(gin.Accounts{
		"foo":    "bar",
		"austin": "1234",
		"lena":   "hello2",
		"manu":   "4321",
	}))
}

func configRouter(env sys_config.WebEndpointEnv, r *gin.Engine) {
	//todo
	//todo context path 配置

	//todo
	//r.LoadHTMLGlob("web/*") //加载目录下的所有html
	//r.Static("/console", "web")

	//r.LoadHTMLGlob("web/*")
	//r.LoadHTMLGlob("web/*.html")
	//r.Delims("<<<",">>>")
	//r.Static("/assets","./static/assets")
	//跨域
	//r.Use(Next())
	//r.Group("/user")
	//r.GET("/:id/:name")
	r.GET("/", func(c *gin.Context) {
		//c.Query()
		//c.HTML(200)200
		c.Header("Content-Type", "text/html; charset=utf-8")
		c.String(http.StatusOK, dataview.DataViewIndex())
		//c.Redirect(302,"/index.html")
	})

	r.GET("dataview/device/:devId", func(c *gin.Context) {
		c.Header("Content-Type", "text/html; charset=utf-8")
		devId := c.Param("devId")

		c.String(http.StatusOK, dataview.DeviceDataView(devId))
	})

}
